﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Text;

public partial class sysadmin_CountManager_CourseCountManager :PowerCreator.LMS.Web.Base.WebBasePage
{
    protected PowerCreator.LMS.ViewQuery.ViewQuery op = new PowerCreator.LMS.ViewQuery.ViewQuery();
    protected string start = DateTime.Now.ToString();
    protected string end = DateTime.Now.ToString();
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            //txt_starttime.Text = DateTime.Today.ToString();
           // txt_endtime.Text = DateTime.Today.ToString();
            ViewState["OrderList"] = "";  //
            ViewState["OrderType"] = " desc ";//排序方式
            string search = GetSearch();
            BinderPager(search);
            BinderRPT(search, 1);
            InitPage();
        }
    }

    protected override void InitPage()
    {
     

       // btnSearch.Text = GetLanageValueByKey("btn_Search", PowerCreator.LMS.Language.LanagetItemType.Page);
        lbl_InfoTitle.Text = GetLanageValueByKey("msg_CourseCount", PowerCreator.LMS.Language.LanagetItemType.Page);

        base.InitPage();

        //btnAddNew.Visible = false;
        //if (IsLicensed(PowerCreator.LMS.Action.Core.ActionInfo.AddJob))
        //    btnAddNew.Visible = true;

    }
    private string GetSearch()
    {
        string sql = "SELECT  CourseName as CourseName,isnull((select sum(ResourceClickNum) from TResource where ResourceID in (select FKCoursersResourceID from TCourseResource where TCourseResource.FKCourseresCourseID=TO_Course.Course_Id )),0) as Counts FROM TO_Course ";

        return sql;
    }

    private void BinderPager(string search)
    {
        AspNetPager1.RecordCount = op.Count(search);
        AspNetPager1.PageSize = LMSPageSize;
        PreAspNetPager(AspNetPager1);
    }

    private void BinderRPT(string search, int pageIndex)
    {
        DataTable dt = new DataTable();
        string orderlist = ViewState["OrderList"].ToString();
        if (!string.IsNullOrEmpty(orderlist))
            search += " order by " + orderlist + ViewState["OrderType"].ToString();
        else
            search += " order by Course_ID desc";


        dt = op.Query(search, "", LMSPageSize, pageIndex);
        ViewState["dt"] = dt;
        rpt_Webvisitnum.DataSource = dt;
        rpt_Webvisitnum.DataBind();
    }
    protected void AspNetPager1_PageChanged(object sender, EventArgs e)
    {
        string search = GetSearch();
        BinderRPT(search, AspNetPager1.CurrentPageIndex);
    }


    protected void rpt_Webvisitnum_ItemCommand(object source, RepeaterCommandEventArgs e)
    {
        if (e.CommandName == "orderby")
        {
            ViewState["OrderList"] = e.CommandArgument.ToString();
            string search = GetSearch();
            BinderRPT(search, AspNetPager1.CurrentPageIndex);
            if (ViewState["OrderType"].ToString() == " desc")
                ViewState["OrderType"] = " asc";
            else
                ViewState["OrderType"] = " desc";
        }
    }




    protected void btnSearch_Click(object sender, EventArgs e)
    {
        string search = GetSearch();
        BinderPager(search);
        BinderRPT(search, 1);
    }
    //protected void btnExport_Click(object sender, EventArgs e)
    //{
    //    DataTable dt = (DataTable)ViewState["dt"];

    //    Excel objExcel = new Excel();
    //    objExcel.ToExcel(dt, this.Page, "访问量统计", "访问量统计信息", "UserLoginLog");
    //}
    //protected void btnExport_All_Click(object sender, EventArgs e)
    //{
    //    DataTable dt = GetAllLst();

    //    Excel objExcel = new Excel();
    //    objExcel.ToExcel(dt, this.Page, "访问量统计", "访问量统计信息", "UserLoginLog");
    //}
}
